<?php
/*
-----新闻分类查询-----
ID      名称
5       首页banner
6       新闻聚焦
7       专题
8       佛讯动态
9       信息公告
10      视频
11      期刊
12      简报
14-23   福建各地的寺院，见“福建寺院”页面
26      慈善公益
27      文化教育
28      下载专区
-----/新闻分类查询-----
*/
    get_header();
    setPostViews(get_the_ID());
    $cat = get_the_category()[0]->term_id === 5 ? get_the_category()[1]->term_id : get_the_category()[0]->term_id; 
    
?>
<!-- 列表模块 -->
<div class="main-container">
        <div class="wrap">
            <div class="breadcrumb">
                <a href="/" title="">首页</a>
                <span class="split">&gt;</span>
                <?php if ($cat == 6) { ?>
                <a href="/news" title="">新闻聚焦</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 8) {?>
                <a href="/buddhism-news" title="">佛讯动态</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 9) {?>
                <a href="/announcement" title="">信息公告</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 10) {?>
                <a href="/video" title="">视频</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 11) {?>
                <a href="/issue" title="">期刊</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 12) {?>
                <a href="/briefing" title="">简报</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat >= 14 && $cat <= 23) {?>
                <a href="/fj-temple/fuzhou-temple" title="">福建寺院</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 26) {?>
                <a href="/welfare" title="">慈善公益</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 27) {?>
                <a href="/education" title="">文化教育</a>
                <span class="split">&gt;</span>
                <?php } else if ($cat == 28) {?>
                <a href="/download" title="">下载专区</a>
                <span class="split">&gt;</span>
                <?php } else {
                    //剩下都是专题的
                    ?>
                    <a href="/topic" title="">专题</a>
                    <span class="split">&gt;</span>
                    <?php
                    $parentCat = get_the_category()[0]->parent;
                ?>
                <a href="/topic/<?php echo get_category($parentCat)->slug; ?>" title=""><?php echo get_cat_name($parentCat); ?></a>
                <span class="split">&gt;</span>
                <?php }?>
                <span class="last">详情</span>
            </div>
            <div class="clearfix">
                <div class="main-block">
                    <div class="news-detail-container <?php if ($cat == 11 || $cat == 12){ echo 'issue-detail-container'; }?>">
                        <h1><?php the_title(); ?></h1>
                        <div class="news-info">
                            <span class="source">来源：<?php echo get_post_meta($post->ID, "source", $single = true); ?></span>
                            
                            <span class="date">发布时间：<?php the_time('Y年m月d日'); ?> </span>
                            <div class="jiathis_style"><span class="jiathis_txt">分享到：</span>
                                <a class="jiathis_button_qzone"></a>
                                <a class="jiathis_button_tsina"></a>
                                <a class="jiathis_button_weixin"></a>
                                <a class="jiathis_button_cqq"></a>
                                <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
                                <a class="jiathis_counter_style"></a>
                            </div>
                            <script type="text/javascript" >
                                var jiathis_config={
                                    summary:"",
                                    shortUrl:false,
                                    hideMore:true
                                }
                            </script>
                            <script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
                        </div>
                        <?php
                           if ($cat == 11 || $cat == 12) {
                                get_template_part('template-parts/issue-content', get_post_format());
                               
                           } else {
                            get_template_part('template-parts/common-content', get_post_format());
                           }
                           if (get_previous_post(true) && get_next_post(true)) {
                        ?>
                        <div class="other-news">
                            <?php 
                                if (get_previous_post(true)) {
                            ?>
                            <p>上一篇：<?php previous_post_link("%link"); ?></p>
                            <?php
                                }
                            ?>
                            <?php 
                                if (get_next_post(true)) {
                            ?>
                            <p>下一篇：<?php next_post_link("%link"); ?></p>
                            <?php
                                }
                            
                            ?>
                        </div>
                        <?}?>
                    </div>
                </div>
                <div class="sidebar">
                    <div class="notice-mod hot-article-mod floor">
                        <div class="head-type02">
                            <?php 
                            if ($cat >= 14 && $cat <= 23) {
                                echo '<h2>其他寺院</h2>';
                            } else {
                                echo '<h2>热门文章</h2>';
                            }
                            ?>
                        </div>
                        <div class="article-main">
                            <?php
                                $queryArg = array();
                                if ($cat >= 14 && $cat <= 23) {
                                    $queryArg = array(
                                        'showposts' => 7,
                                        "orderby" => "rand",
                                        "cat" => array(14,15,16,17,18,19,20,21,22,23)
                                    );
                                } else if (get_category($parentCat)->parent == 7) {
                                    //是专题详情
                                    $thisTopicCatArray = get_categories("child_of=".$parentCat);
                                    
                                    $queryArg = array(
                                        'showposts' => 7,
                                        "meta_key" => "post_views_count",
                                        "orderby" => "meta_value_num",
                                        "order" => "DESC",
                                        "cat" => array($thisTopicCatArray[0]->term_id, $thisTopicCatArray[1]->term_id)
                                    );
                                } else {
                                    $queryArg = array(
                                        'showposts' => 7,
                                        "meta_key" => "post_views_count",
                                        "orderby" => "meta_value_num",
                                        "order" => "DESC",
                                        "cat" => $cat
                                    );
                                }
                                query_posts($queryArg);
                                if (have_posts()) {
                                    the_post();
                                
                            ?>
                            <div class="article-first clearfix">
                                <a class="img-block" href="<?php the_permalink(); ?>" title="">
                                    <?php the_post_thumbnail(array(120, 73)); ?>
                                </a>
                                <div class="art-right">
                                    <h3><a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a></h3>
                                    <p class="date"><?php the_time('Y-m-d'); ?></p>
                                </div>
                            </div>
                            <?php
                            }
                            ?>
                            <ul>
                                <?php
                                for ($i = 0; $i < 7; $i++) {
                                    if (have_posts()) {
                                        the_post();
                                    ?>
                                <li>
                                    <i></i>
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </li>
                                    <?php
                                    } else {
                                        break;
                                    }
                                }
                                ?>
                            </ul>
                        </div>
                    </div>
                    <?php get_template_part('template-parts/sidebar-topic', get_post_format()); ?>
                </div>
            </div>
        </div>
    </div>
<?php
    get_footer();
?>
<script>
(function() {
    //根据分类给menu加二态
    <?php if ($cat == 6) { ?>
    $('.menu > li').eq(1).addClass('current');
    <?php } else if ($cat == 7) {?>
        $('.menu > li').eq(2).addClass('current');
    <?php } else if ($cat == 8) {?>
        $('.menu > li').eq(4).addClass('current');
    <?php } else if ($cat == 10) {?>
        $('.menu > li').eq(5).addClass('current');
    <?php } else if ($cat == 11 || $cat == 12) {?>
        $('.menu > li').eq(9).addClass('current');
    <?php } else if ($cat >= 14 && $cat <= 23) {?>
        $('.menu > li').eq(6).addClass('current');
    <?php } else if ($cat == 26) {?>
        $('.menu > li').eq(7).addClass('current');
    <?php } else if ($cat == 27) {?>
        $('.menu > li').eq(8).addClass('current');
    <?php } else if ($cat == 28) {?>
        $('.menu > li').eq(-1).addClass('current');
    <?php }?>
})();
</script>
<?php 
if ($cat == 11 || $cat == 12) {
?>
<script>
        var iSwiper = new Swiper('#issue-thumb-container', {
            slidesPerGroup: 1,
            slidesPerView: 11,
            roundLength: true,
            onlyExternal: true
        });
        var $page = $('#issue-page-container');
        var $thumb = $('#issue-thumb-container');
        var thumbLen = $thumb.find('li').length;
        var curIndex = 0;
        var winW = $(window).width();
        var winH = $(window).height();
        var issueImg = new Image();
        issueImg.src = '<?php echo get_post_gallery_images()[0]; ?>';
        var issueImgW = issueImg.width;
        var issueImgH = issueImg.height;

        $thumb.find('.slide-prev').click(function() {
            iSwiper.swipePrev();
            curIndex--;
            if (curIndex < 0) {
                curIndex = thumbLen - 1;
                iSwiper.swipeTo(curIndex);
            }
            $thumb.find('li').eq(curIndex).addClass('on').siblings().removeClass('on');
            $page.find('img').attr('src', $thumb.find('li').eq(curIndex).find('img').attr('src'));
        });
        $thumb.find('.slide-next').click(function() {
            iSwiper.swipeNext();
            curIndex++;
            if (curIndex > thumbLen - 1) {
                curIndex = 0;
                iSwiper.swipeTo(curIndex);
            }
            $thumb.find('li').eq(curIndex).addClass('on').siblings().removeClass('on');
            $page.find('img').attr('src', $thumb.find('li').eq(curIndex).find('img').attr('src'));
        });

        function switchPage() {
            $page.find('img').attr('src', $thumb.find('li').eq(curIndex).find('img').attr('src'));
            iSwiper.swipeTo(curIndex);
        }

        $page.find('.slide-prev').click(function() {
            curIndex--;
            if (curIndex < 0) {
                curIndex = thumbLen - 1;
            }
            $thumb.find('li').eq(curIndex).addClass('on').siblings().removeClass('on');
            switchPage();
        });
        $page.find('.slide-next').click(function() {
            curIndex++;
            if (curIndex > thumbLen - 1) {
                curIndex = 0;
            }
            $thumb.find('li').eq(curIndex).addClass('on').siblings().removeClass('on');
            switchPage();
        });
        $thumb.find('li').click(function() {
            curIndex = $(this).index();
            switchPage();
            $(this).addClass('on').siblings().removeClass('on');
        });

        //放大
        $('.issue-fullpage').click(function() {
            if (!$(this).hasClass('on')) {
                $(this).addClass('on');
                iSwiper.reInit();
                $('.issue-detail-container, body').addClass('full');
                setSizeAtFullMode(true);
            } else {
                $(this).removeClass('on');
                $('.issue-detail-container, body').removeClass('full');
                setSizeAtFullMode();
            }
        });

        //计算全屏模式下图片尺寸
        function setSizeAtFullMode(isSet) {
            if (isSet) {
                if (winW * 0.8 * issueImgH / issueImgW + 137 > winH) {
                    var realH = winH - 177 > issueImgH ? issueImgH - 177 : winH - 177;
                    $('.issue-show-con').width(realH * issueImgW / issueImgH).height(realH);
                } else {
                    $('.issue-show-con').width(winW * 0.8).height(winW * 0.8 * issueImgH / issueImgW);
                }

            } else {
                $('.issue-show-con').css({
                    width: '',
                    height: ''
                });
            }
        }

        $(document).keyup(function(e){
            var key =  e.which;
            if (key == 27) {
                $('.issue-fullpage').trigger('click');
            }
        });
    </script>
    <?php }?>
</body>
</html>